package com.batchengine.pool;

import static com.batchengine.pool.WorkerPool.DEFAULT_MAX_WORKERS;
import static com.batchengine.pool.WorkerPool.DEFAULT_MIN_WORKERS;
import com.batchengine.worker.ConsumerFactory;
import com.batchengine.worker.DataGatherer;
import com.batchengine.worker.ScheduledDataGatherer;

/**
 * Created by sunil.incubator@yahoo.com.
 * User: sunil.kalva
 * Date: Jul 10, 2009
 */
public class WorkerPoolFactory {

    private WorkerPoolFactory() {

    }

    public static WorkerPool createProducerConsumerPool(int minWorkers, int maxWorkers, Long taskId, WorkerFactory workerFactory, DataGatherer dataGatherer) {
        ProducerConsumerWorkerPool workerPool = new ProducerConsumerWorkerPool(minWorkers, maxWorkers, dataGatherer, workerFactory);
        workerPool.setTaskId(taskId);
        return workerPool;
    }

    public static WorkerPool createProducerConsumerPool(int minWorkers, int maxWorkers, Long taskId, WorkerFactory workerFactory, ScheduledDataGatherer dataGatherer) {
        ProducerConsumerWorkerPool workerPool = new ProducerConsumerWorkerPool(minWorkers, maxWorkers, dataGatherer, workerFactory);
        workerPool.setTaskId(taskId);
        return workerPool;
    }

    public static WorkerPool createProducerConsumerPool(int minWorkers, int maxWorkers, Long taskId, DataGatherer dataGatherer) {
        return createProducerConsumerPool(minWorkers, maxWorkers, taskId, new ConsumerFactory(dataGatherer.getWorkSelector().getWorkQ()), dataGatherer);
    }

    public static WorkerPool createProducerConsumerPool(int minWorkers, int maxWorkers, Long taskId, ScheduledDataGatherer dataGatherer) {
        return createProducerConsumerPool(minWorkers, maxWorkers, taskId, new ConsumerFactory(dataGatherer.getWorkSelector().getWorkQ()), dataGatherer);
    }

    public static WorkerPool createProducerConsumerPool(Long taskId, DataGatherer dataGatherer) {
        return createProducerConsumerPool(DEFAULT_MIN_WORKERS, DEFAULT_MAX_WORKERS, taskId, new ConsumerFactory(dataGatherer.getWorkSelector().getWorkQ()), dataGatherer);
    }

    public static WorkerPool createProducerConsumerPool(Long taskId, ScheduledDataGatherer dataGatherer) {
        return createProducerConsumerPool(DEFAULT_MIN_WORKERS, DEFAULT_MAX_WORKERS, taskId, new ConsumerFactory(dataGatherer.getWorkSelector().getWorkQ()), dataGatherer);
    }

    public static WorkerPool createExecutorPool(int minWorkers, int maxWorkers, long taskId, WorkerFactory workerFactory) {
        return new ExecutorWorkerPool(minWorkers, maxWorkers, taskId, workerFactory);
    }

    public static WorkerPool createExecutorPool(int minWorkers, int maxWorkers, long taskId) {
        return createExecutorPool(minWorkers, maxWorkers, taskId, new ExecutorWorkerFactory());
    }

    public static WorkerPool createExecutorPool(long taskId) {
        return createExecutorPool(DEFAULT_MIN_WORKERS, DEFAULT_MAX_WORKERS, taskId, new ExecutorWorkerFactory());
    }
}
